package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.PortDriver;
import com.bocloud.cmp.driver.providers.intf.PortProvider;
import com.bocloud.cmp.driver.providers.os.OSDriver.Version;
import com.bocloud.cmp.driver.providers.os.OSPortDriver;
import com.bocloud.cmp.model.Butler;
import com.bocloud.cmp.model.PortModel;
import com.bocloud.common.model.BsmResult;

@Service("portProvider")
public class PortProviderImpl implements PortProvider {

	@Override
	public BsmResult create(String vendor, String region, PortModel portModel) {
		Butler butler = Configuration.instance().getConfig(vendor);
		PortDriver driver = new OSPortDriver(butler.getUrl(), butler.getUsername(), butler.getPassword(),
				butler.getTenant(), butler.getDomainName(), butler.getProjectName(),
				Version.valueOf(butler.getVersion()));
		BsmResult result = driver.create(portModel);
		return result;
	}

	@Override
	public BsmResult remove(String portId, String vendor, String region) {
		Butler butler = Configuration.instance().getConfig(vendor);
		PortDriver driver = new OSPortDriver(butler.getUrl(), butler.getUsername(), butler.getPassword(),
				butler.getTenant(), butler.getDomainName(), butler.getProjectName(),
				Version.valueOf(butler.getVersion()));
		BsmResult result = driver.remove(portId);
		return result;
	}

	@Override
	public BsmResult detail(String portId, String vendor, String region) {
		Butler butler = Configuration.instance().getConfig(vendor);
		PortDriver driver = new OSPortDriver(butler.getUrl(), butler.getUsername(), butler.getPassword(),
				butler.getTenant(), butler.getDomainName(), butler.getProjectName(),
				Version.valueOf(butler.getVersion()));
		BsmResult result = driver.detail(portId);
		return result;
	}

}
